package com.datasecops.scannerservices.extractwatermark;

import com.datasecops.scannerservices.configurationfiles.WatermarkingConfiguration;
import com.datasecops.scannerservices.watermark.JNILinuxSo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.sql.SQLException;

/**数据库水印的提取
 * 通用
 * @author: GeXiaoLong
 * @time: 2023/1/3 14:36
 */
@Service
@Slf4j
public class ExtractWatermark {
    @Resource
    private JNILinuxSo jniLinuxSo;
    @Resource
    private ExtractionConfiguration extractionConfiguration;

    public WatermarkingConfiguration text(String tableName) throws IOException, SQLException {
        log.error("水印提取配置参数的生成进来了吗?");
        WatermarkingConfiguration watermarkingConfiguration = new WatermarkingConfiguration();
        /*这些参数是要写成动态的*/
        watermarkingConfiguration.setHOST("10.26.18.61");
        watermarkingConfiguration.setPORT("3306");
        watermarkingConfiguration.setUSER("root");
        watermarkingConfiguration.setPASSWORD("sc.9102");
        watermarkingConfiguration.setDBNAME("text");
        String OperType = "OtExtract";
        String ExtractTableName = tableName;
        //换到提取库
        String dbname = "WatermarkExtraction";
        String dbName = watermarkingConfiguration.getDbName()+dbname;
        watermarkingConfiguration.setDbName(dbName);

        String WmType = "WmFakeRow";//水印的类型
        String TraceWmEmbedChars = "DSO Database IPR, 2022.11.11, China Beijing. To:China Mobile. Usage:Collaboration, Validity:2200.12.31.";
        watermarkingConfiguration.setEMBEDTABLENAME(ExtractTableName);
//        String dbName = watermarkingConfiguration.getDbName()+DbName;
//        watermarkingConfiguration.setDbName(dbName);
        String operType = watermarkingConfiguration.getOperType()+OperType;
        watermarkingConfiguration.setOperType(operType);
        if ("OtExtract".equalsIgnoreCase(OperType)){
            String embedTableName = watermarkingConfiguration.getExtractTableName()+ExtractTableName;
            watermarkingConfiguration.setExtractTableName(embedTableName);
            String extractWmFileNameName = watermarkingConfiguration.getExtractWmFileNameName()+ExtractTableName+".txt";
            watermarkingConfiguration.setExtractWmFileNameName(extractWmFileNameName);
            String extractAuxInfoFileName = watermarkingConfiguration.getExtractAuxInfoFileName()+ExtractTableName+".txt";
            watermarkingConfiguration.setExtractAuxInfoFileName(extractAuxInfoFileName);
            String embractWmFileNameName = watermarkingConfiguration.getEmbedWmFileName()+ExtractTableName+".txt";
            watermarkingConfiguration.setEmbedWmFileName(embractWmFileNameName);
            String embractAuxInfoFileName = watermarkingConfiguration.getEmbedAuxInfoFileName()+ExtractTableName+".txt";
            watermarkingConfiguration.setEmbedAuxInfoFileName(embractAuxInfoFileName);
        }
        String runOutFileName = watermarkingConfiguration.getRunOutFileName()+ExtractTableName+".log";
        watermarkingConfiguration.setRunOutFileName(runOutFileName);
        String tableDesFileName = watermarkingConfiguration.getTableDesFileName()+ExtractTableName+".txt";
        watermarkingConfiguration.setTableDesFileName(tableDesFileName);
        String wmType = watermarkingConfiguration.getWmType()+WmType;
        watermarkingConfiguration.setWmType(wmType);
        String traceWmEmbedChars = watermarkingConfiguration.getTraceWmEmbedChars()+TraceWmEmbedChars;
        watermarkingConfiguration.setTraceWmEmbedChars(traceWmEmbedChars);
        log.error("水印提取配置参数的生成进来了吗?2");
        extractionConfiguration.diskDropFile(watermarkingConfiguration);

        try {
            Thread.sleep(1000);
            jniLinuxSo.text();
        } catch (Exception e) {
            log.error("出错了2",e);
        }

        return watermarkingConfiguration;
    }


    public static void main(String[] args) throws IOException, SQLException {
        String tableName = "dlp_datarisksit_assessment_question_bank";
        ExtractWatermark extractWatermark = new ExtractWatermark();
        extractWatermark.text(tableName);
    }


}
